﻿Public Class clsInhTrMaterialProdukcyjny
    Inherits clsTrMaterialProdukcyjny

#Region "Attributes"

    Private mvarPracownik As clsPracownik
    Private mvarPakowanie As clsPakowanie
    Private mvarMaterial As clsInhMaterial

#End Region

#Region "Properties"

    Public Property Pracownik() As clsPracownik
        Get
            Return mvarPracownik
        End Get
        Set(ByVal value As clsPracownik)
            mvarPracownik = value
        End Set
    End Property

    Public Property Pakowanie() As clsPakowanie
        Get
            Return mvarPakowanie
        End Get
        Set(ByVal value As clsPakowanie)
            mvarPakowanie = value
        End Set
    End Property

    Public Property Material() As clsInhMaterial
        Get
            Return mvarMaterial
        End Get
        Set(ByVal value As clsInhMaterial)
            mvarMaterial = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()
        MyBase.New()
        mvarPracownik = New clsPracownik()
        mvarPakowanie = New clsPakowanie()
        mvarMaterial = New clsInhMaterial()
    End Sub

    Public Sub New(ByVal ID As Integer, ByVal lvarDbHolder As clsDataBase)
        MyBase.New(ID, lvarDbHolder, VAR_ERROR_HANDLER)

        mvarPracownik = New clsPracownik(MyBase.PracownikId.ToString(), lvarDbHolder, VAR_ERROR_HANDLER)
        mvarPakowanie = New clsPakowanie(MyBase.PakowanieId.ToString(), lvarDbHolder, VAR_ERROR_HANDLER)
        mvarMaterial = New clsInhMaterial(MyBase.MaterialId, lvarDbHolder)

    End Sub

    Public Overloads Sub Save(ByVal lvarDbHolder As clsDataBase, ByVal StatusId As Integer, ByVal ZlecenieId As Integer, ByVal PozycjaZleceniaId As Integer)
        MyBase.Save(lvarDbHolder, VAR_ERROR_HANDLER)
        If StatusId = 1 Then
            clsInhTrZlecenie.ZmienStatus(lvarDbHolder, ZlecenieId, 4)
            clsInhTrPozycjaZlecenia.ZmienStatus(lvarDbHolder, PozycjaZleceniaId, 4)
        End If
    End Sub

    Public Overloads Sub Delete(ByVal lvarDbHolder As clsDataBase)
        MyBase.Delete(lvarDbHolder, VAR_ERROR_HANDLER)
    End Sub

    Public Overrides Function ToString() As String
        Return MyBase.Id & "- waga: " & MyBase.Ilosc
    End Function

    Shared Function Sprawdzenie(lvarDbHolder As clsDataBase, IdSchematu As Integer) As Boolean

        Dim lvarReader As OdbcDataReader = Nothing
        Dim lvarReturn As Boolean

        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_tracking", "cls_material_produkcyjny", 1, VAR_ERROR_HANDLER)
            '      

            With lvarSqlRunner
                .AddParameter("p_schemat_id", IdSchematu.ToString())
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                lvarReturn = True
            End If

        End If

        Return lvarReturn

    End Function

#End Region

End Class
